<div class="col-lg-12">
    @include('admin.contents.bar')
    <section class="panel">
        {{ Form::open(array('method' => 'put', 'route' => array('admin.contents.categories.update', $category->id),'class'=>'form-horizontal', 'data-validate'=>"parsley")) }}
        <header class="panel-heading">
            <div class="pull-left"><i class="fa fa-edit fa-lg"></i> Edit Category</div>
        </header>
        <div class="panel-body">
            @if ($errors->any())
                <ul class="alert alert-danger">
                    {{ implode('', $errors->all('<p>:message</p>')) }}
                </ul>
            @endif
            <div class="form-group">
                <label class="col-lg-3 control-label">Name</label>
                <div class="col-lg-8">
                    <input type="text" class="bg-focus form-control parsley-validated" data-required="true" placeholder="Name" name="name" value="{{$category->name}}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-3 control-label">Active</label>
                <div class="col-lg-8">
                    <div class="checkbox">
                        <input type="checkbox" name="active" value="Y" @if($category->active=='Y') checked="checked" @endif >
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="col-lg-9 col-lg-offset-3">
                    <button class="btn btn-white btn-primary" type="submit">Save Category</button>
                    <a class="btn" href="{{ URL::to('admin/contents/categories') }}">Cancel</a>
                </div>
            </div>
        </div>
        {{ Form::close() }}
    </section>
    <section class="panel">
        <header class="panel-heading"><i class="fa fa-edit"></i> {{$category->name}} (Featured) <button class="btn btn-primary pull-right" id="saveOrder" type="button" style="display:none;">Save Order</button></header>
        <div class="alert" id="featuredAlert" style="display:none;margin-top:15px;"></div>
        <div class="table-responsive">
            <table class="table table-striped m-b-none">
                <thead>
                    <tr>
                        <th width="5%"></th>
                        <th width="5%">id</th>
                        <th width="35%">name</th>
                        <th width="10%">active</th>
                        <th width="50%"></th>
                    </tr>
                </thead>
                <tbody id="gallery-order-list">
                    @if($categoryFeatured)
                        @foreach($categoryFeatured as $key => $featured)
                            <tr style="width:100%" order-item="{{$featured->contentID}}">
                                <td><i class="fa fa-bars text-default"></i></td>
                                <td>{{$featured->contentID}}</td>
                                <td>{{$featured->title}}</td>
                                <td>                            
                                    <a href="#" @if($featured->active=='Y') class="active" @endif>
            	                        @if($featured->active=='Y')
        	                                <i class="fa fa-check fa-lg text-success text-active"></i>
        	                            @else
                	                        <i class="fa fa-times fa-lg text-danger text"></i>
                                        @endif
                                    </a>
                                </td>
                                <td class="td-actions">
                                   <a class="btn btn-small btn-primary pull-right" href="{{ URL::route('admin.contents.edit', $featured->contentID)}}"><i class="fa fa-edit"></i></a>
                                  {{ Form::open(array('url' => array('admin/contents/categories/remove-featured'), 'method' => 'post', 'class'=>"pull-right")) }}
                                       <button button="submit" class="btn btn-small btn-inverse"><i class="fa fa-edit"></i> Remove From Featured</button>
                                       <input type="hidden" name="contentID" value="{{$featured->contentID}}">
                                       <input type="hidden" name="categoryID" value="{{$featured->categoryID}}">
                                   {{ Form::close() }}
                                </td>
                            </tr>
                        @endforeach
                    @else
                        <tr style="width:100%;">
                            <td colspan="5" style="text-align:center">No featured</td>
                        </tr>
                    @endif
                </tbody>
            </table>
        </div>
    </section>
    <section class="panel">
        <header class="panel-heading"><i class="fa fa-edit"></i> Category Contents</header>
        <div class="table-responsive">
            <table class="table table-striped m-b-none" data-ride="datatables">
                <thead>
                    <tr>
                        <th width="5%">id</th>
                        <th width="45%">name</th>
                        <th width="10%">active</th>
                        <th width="15%">created_at</th>
                        <th width="25%"></th>
                    </tr>
                </thead>
                <tbody>
                @if($contents)
                    @foreach($contents as $key => $content)
                        <tr>
                            <td>{{$content->contentID}}</td>
                            <td>{{$content->title}}</td>
                            <td>                            
                                <a href="#" @if($content->active=='Y') class="active" @endif>
        	                        @if($content->active=='Y')
    	                                <i class="fa fa-check fa-lg text-success text-active"></i>
    	                            @else
            	                        <i class="fa fa-times fa-lg text-danger text"></i>
                                    @endif
                                </a>
                            </td>
                            <td>{{$content->created_at}}</td>
                            <td class="td-actions">
                                {{ Form::open(array('url' => array('admin/contents/categories/featured'), 'method' => 'post', "class"=>"pull-left")) }}
                                    <button type="submit" class="btn btn-small btn-warning"><i class="fa fa-edit"></i> Add To Featured</button>
                                    <input type="hidden" name="contentID" value="{{$content->contentID}}">
                                    <input type="hidden" name="categoryID" value="{{$content->categoryID}}">
                                {{ Form::close() }}<!--
                                --><a class="btn btn-small btn-primary" href="{{ URL::route('admin.contents.edit', $content->contentID)}}"><i class="fa fa-edit"></i></a><!--
                				-->{{ Form::open(array('route' => array('admin.contents.destroy', $content->contentID), 'method' => 'delete', "class"=>"pull-right")) }}
                                       <button class="btn btn-small btn-danger"><i class="fa fa-trash-o"></i></button>
                                   {{ Form::close() }}<!--</i></a>-->
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
    </section>
</div>
@section('extra-javascript')
<script src="{{ asset('js/datatables/jquery.dataTables.min.js')}}"></script>
<script>
// datatable
$('[data-ride="datatables"]').each(function() {
	var oTable = $(this).dataTable( {
		"sDom": "<'row'<'col-sm-6'l><'col-sm-6'f>r>t<'row'<'col-sm-6'i><'col col-sm-6'p>>",
		"sPaginationType": "full_numbers"
	} );
});
</script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<script>
jQuery(function ($) {
    $.ajaxSetup({
        headers: {
            'X-CSRF-Token': $('.form-horizontal input[name="_token"]').val()
        }
    });
});
$("#gallery-order-list").sortable({
    sort: function(event, ui) {  
        ui.helper.css({'top' : ui.position.top + $(window).scrollTop() + 'px'});
    },
    item:"tr",
    update: function(event, ui) {   
        $("#saveOrder").show();
        $("#saveOrder").fadeTo('fast',0.33);
        $("#saveOrder").fadeTo('fast',1);
        $("#saveOrder").fadeTo('fast',0.33);
        $("#saveOrder").fadeTo('fast',1);
        $("#saveOrder").fadeTo('fast',0.33);
        $("#saveOrder").fadeTo('fast',1);
        
   
        $("#saveOrder").click(function() {
            var finish_order = "";
            first = true;
            $('#gallery-order-list tr').each(function(){
                if(!first) {
                    finish_order += "&";
                }
                finish_order += "mySortable[]="+$(this).attr('order-item');
                first = false;
            });
        //    resta postear y ordernar
            $.ajax({
                type:"POST",
                url: "{{url('admin/contents/categories/order-featured')}}",
                data:{categoryID:"{{$category->id}}",newOrderItems:finish_order},
                success:function(data) {
                    $("#featuredAlert").attr('class','alert');
                    if(data.success==true) {
                        $("#featuredAlert").addClass('alert-success');
                        $("#featuredAlert").html("<p>"+data.message+"</p>");
                    } else {
                        $("#featuredAlert").addClass('alert-danger');
                        $("#featuredAlert").html("<p>"+data.message+"</p>");
                    }
                    $("#featuredAlert").show();
                    $("#featuredAlert").delay(2000).fadeOut(1000);
                }
            });
        });    
    }
});
</script>
@stop

